package cn.biplam.front.component.data.common;

import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.Operator;
import cn.biplam.common.client.OperatorResult;
import cn.biplam.common.opcode.SysManageCode.SysLanguageCode;
import cn.biplam.common.opcode.SysManageCode.UserOptCode;
import cn.biplam.common.struc.SysStruc.UserStruc;
import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;

/**
 * 消息信息数据获取组件
 * @author XiaoRuxing 2009-5-6下午09:09:32
 * @version 1.0
 */
public class CaptionComp {

	/**
	 * 返回依据用户语言类型获取的标题文字
	 * @param mUser       	用户信息类
	 * @param sButtonCode 	按钮代码
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String get(UserInfo mUser,String sButtonCode) throws ErrorMessage{
		if(mUser==null){
			throw new ErrorMessage("user is null!");
		}
		DataFilter filter=new DataFilter();
		filter.put("user_language", mUser.getUserLanguage());
		filter.put("caption_id", sButtonCode);
		OperatorResult result=Operator.get(SysLanguageCode.Get_Caption, mUser.getUserID(), filter);
		String caption = result.getValue();
		if(TOOLS.StringIsEmpty(caption)){
			caption = sButtonCode;
		}
		return caption;
	}

	/**
	 * 返回依据用户语言类型获取的标题文字
	 * @param userId		用户ID
	 * @param sButtonCode	标题代码
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String get(String userId,String sButtonCode) throws ErrorMessage{
		UserInfo mUser = new UserInfo();
		mUser.setUserID(userId);
		DataFilter filter =new DataFilter();
		filter.put(UserStruc.USERID, userId);
		OperatorResult rs = Operator.get(UserOptCode.Query_User_By_Id, 
				userId, 
				filter
		);
		mUser.setUserLanguage(rs.getValue(UserStruc.LANG));
		return CaptionComp.get(mUser, sButtonCode);
	}
}
